﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    [ServiceContract]
    class PublicFunction
    {
        //实例化数据层
        DAL.DALMethod myDAL = new DAL.DALMethod();
        /// <summary>
        /// 公共分页查询方法
        /// </summary>
        /// <param name="strTblName">表名</param>
        /// <param name="strGetFields">需要返回的列</param>
        /// <param name="strFldName">排序的字段名</param>
        /// <param name="intPageSize">页尺寸</param>
        /// <param name="intPageIndex">页码</param>
        /// <param name="blDoCount">返回记录总数, 非 0 值则返回</param>
        /// <param name="blOrderType">设置排序类型, 非 0 值则降序</param>
        /// <param name="strWhere">查询条件</param>
        /// <returns></returns>
        [OperationContract]//每页显示的DATA        
        public DataSet PublicPagingSelect(string strTblName,
                                          string strGetFields,
                                          string strFldName,
                                          int intPageSize,
                                          int intPageIndex,
                                          bool blDoCount,
                                          bool blOrderType, string strWhere)
        {
            SqlParameter[] mySqlParameters = {
                                        new SqlParameter("@tblName",SqlDbType.VarChar,4000 ),//表名
                                        new SqlParameter("@strGetFields",SqlDbType.VarChar,4000 ),//需要返回的列
                                        new SqlParameter("@fldName",SqlDbType.VarChar,255 ),//排序的字段名
                                        new SqlParameter("@PageSize",SqlDbType.Int ),//页尺寸
                                        new SqlParameter("@PageIndex",SqlDbType.Int ),//页码
                                        new SqlParameter("@doCount",SqlDbType.Bit ),//返回记录总数, 非 0 值则返回
                                        new SqlParameter("@OrderType",SqlDbType.Bit ),//设置排序类型, 非 0 值则降序
                                        new SqlParameter("@strWhere",SqlDbType.VarChar,1500 ),//查询条件 (注意: 不要加 where)
                                             };

            mySqlParameters[0].Value = strTblName;
            mySqlParameters[1].Value = strGetFields;
            mySqlParameters[2].Value = strFldName;
            mySqlParameters[3].Value = intPageSize;
            mySqlParameters[4].Value = intPageIndex;
            mySqlParameters[5].Value = blDoCount;
            mySqlParameters[6].Value = blOrderType;
            mySqlParameters[7].Value = strWhere;
            DataSet myDataSet = myDAL.QueryDataSet("PublicPagingSelect", mySqlParameters);
            return myDataSet;
        }
        

    }
}
